//
//  TXFEmojiCollectionView.swift
//  weibo飞飞
//
//  Created by 田侠飞 on 16/7/4.
//  Copyright © 2016年 田侠飞. All rights reserved.
//

import UIKit



class TXFEmojiCollectionView: UICollectionView {

 let cellID = "cell"
    
    override init(frame: CGRect, collectionViewLayout layout: UICollectionViewLayout) {
        
        super.init(frame: frame, collectionViewLayout: UICollectionViewFlowLayout())
        
        setupUI()
        
    }
 required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    
    func setupUI(){
    

 
    dataSource = self
        
    registerClass(TXFEmoticonCollectionViewCell.self, forCellWithReuseIdentifier: cellID)
    let  layout = collectionViewLayout as! UICollectionViewFlowLayout
        
    layout.itemSize  = CGSize(width: SCREENW, height: 179)
        
        layout.minimumInteritemSpacing = 0
        
        layout.minimumLineSpacing = 0
        //滚动方向:
        layout.scrollDirection = .Horizontal
    }
    
    
    

}


extension TXFEmojiCollectionView : UICollectionViewDataSource{

    func numberOfSectionsInCollectionView(collectionView: UICollectionView) -> Int {
        
        return TXFEmoticonTools.sharedTools.allEmoticons.count
        
    }
    func collectionView(collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
        return TXFEmoticonTools.sharedTools.allEmoticons[section].count
    }

  
    func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {
        
        let cell = collectionView.dequeueReusableCellWithReuseIdentifier(cellID, forIndexPath: indexPath)as!TXFEmoticonCollectionViewCell

        
        cell.emoticons = TXFEmoticonTools.sharedTools.allEmoticons[indexPath.section][indexPath.item]
        return cell
        
    }




}

